<template>
  <div class="col-md-8">
    <h3 class="reply">评论回复：</h3>
    <h2 v-if="comments && comments.length == 0">
      暂无评论，点击左侧添加评论！！！
    </h2>
    <ul class="list-group">
      <li
        class="list-group-item"
        @mouseenter="handleMouse"
        @mouseleave="handleMouse"
        v-for="(comment, index) in comments"
        :key="index"
      >
        <div class="handle">
          <a href="javascript:" v-if="isHover" @click="del(index)">删除</a>
        </div>
        <p class="user">
          <span>{{ comment.name }}</span>
          <span>说:{{ comment.content }}</span>
        </p>
        <p class="centence"></p>
      </li>
    </ul>
  </div>
</template>

<script>
export default {
  name: "CommentList",
  //接收父组件属性
  props: {
    comments: Array,
  },
  data() {
    return { isHover: false };
  },
  methods: {
    //删除评论
    del: function(index) {
      //dispatch触发action
      this.$store.dispatch('delComment',index);
    },
    //移入移出事件
    handleMouse: function() {
      this.isHover = !this.isHover;
    }
  }
};
</script>

<style scoped>
.reply {
  margin-top: 0;
}

li {
  transition: 0.5s;
  overflow: hidden;
}

.handle {
  width: 40px;
  border: 1px solid #ccc;
  background: #fff;
  position: absolute;
  right: 10px;
  top: 1px;
  text-align: center;
}

.handle a {
  display: block;
  text-decoration: none;
  color: red;
}

.list-group-item .centence {
  padding: 0 50px;
}

.user {
  font-size: 22px;
}
</style>
